#include "abaqus_inp_parser.h"
#include <iostream>

int main() {
    AbaqusInpParser parser("R:/sjd.inp");
    Assembly assembly = parser.parse();
    
    auto instances = assembly.getInstances();
    std::cout << "Assembly contains " << instances.size() << " instances" << std::endl;
    
    for (const auto& instance_pair : instances) {
        const auto& instance_name = instance_pair.first;
        const auto& instance = instance_pair.second;
        auto part = instance->getRefPart();
        
        std::cout << "\nInstance '" << instance_name << "' references part '" << part->getName() << "'" << std::endl;
        
        auto translate = instance->getTranslation();
        std::cout << "  Translation: [" << translate[0] << ", " << translate[1] << ", " << translate[2] << "]" << std::endl;
        
        auto rotation = instance->getRotation();
        if (!rotation.empty()) {
            std::cout << "  Rotation: axis_point1=[" << rotation[0][0] << ", " << rotation[0][1] << ", " << rotation[0][2] << "], "
                      << "axis_point2=[" << rotation[1][0] << ", " << rotation[1][1] << ", " << rotation[1][2] << "], "
                      << "angle=" << rotation[2][0] << std::endl;
        }
        
        std::cout << "  Part has " << part->getNodeArray().rows << " nodes and " << part->getElemTotalNum() << " elements" << std::endl;
        
        auto elem_types = part->getElemTypes();
        std::cout << "  Element types: ";
        if (elem_types.empty()) {
            std::cout << "None" << std::endl;
        } else {
            for (const auto& type : elem_types) {
                std::cout << type.first << "(" << type.second.rows << ") ";
            }
            std::cout << std::endl;
        }
        
        // Example: Access specific element information
        auto elem_info_map = part->getElemInfoMap();
        if (!elem_info_map.empty()) {
            // Get first element ID
            int first_elem_id = elem_info_map.begin()->first;
            auto elem_info = instance->getElemInfo(first_elem_id);
            
            if (!elem_info.first.empty()) {
                std::cout << "\nExample element " << first_elem_id << ":" << std::endl;
                std::cout << "  Type: " << elem_info.first << std::endl;
                std::cout << "  Node indices: ";
                for (int node_id : elem_info.second) {
                    std::cout << node_id << " ";
                }
                std::cout << std::endl;
                
                std::cout << "  Node coordinates:" << std::endl;
                for (int node_id : elem_info.second) {
                    auto coord = instance->getNodeCoord(node_id);
                    std::cout << "    " << node_id << ": [" << coord[0] << ", " << coord[1] << ", " << coord[2] << "]" << std::endl;
                }
            }
        }
    }
    
    return 0;
}